package org.mzx.shortLink.adminn.remoteApi.Api;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.mzx.shortLink.adminn.remoteApi.dto.Request.recycleBinAddDtoReq;
import org.mzx.shortLink.adminn.remoteApi.dto.Response.ShortLinkRecycleBinPageReqDTO;
import org.mzx.shortLink.adminn.remoteApi.dto.Response.TLinkPageDtoResp;
import org.mzx.shortLink.starter.convention.Result.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.HashMap;
@Component
public class RecycleBinApi {

    public Result<Void> saveRecycleBin(recycleBinAddDtoReq requestParam) {
        String result = HttpUtil.post("http://localhost:8001/api/short-link/v1/recycle-bin/save", JSONObject.toJSONString(requestParam));
        return JSONObject.parseObject(result, new TypeReference<>() {
        });
    }

    /**
     * 分页查询回收站短链接
     */

    public Result<Page<TLinkPageDtoResp>> pageShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("GidList",requestParam.getGidList());
        String result = HttpUtil.get("http://localhost:8001/api/short-link/v1/recycle-bin/page", paramMap);
        return JSONObject.parseObject(result, new TypeReference<>() {
        });
    }

    /**
     * 恢复短链接
     */

    public Result<Void> recoverRecycleBin(@RequestBody recycleBinAddDtoReq requestParam) {
        String result = HttpUtil.post("http://localhost:8001/api/short-link/v1/recycle-bin/recover", JSONObject.toJSONString(requestParam));
        return JSONObject.parseObject(result, new TypeReference<>() {
        });
    }

    /**
     * 移除短链接
     */
    public Result<Void> removeRecycleBin(@RequestBody recycleBinAddDtoReq requestParam) {
        String result = HttpUtil.post("http://localhost:8001/api/short-link/v1/recycle-bin/remove", JSONObject.toJSONString(requestParam));
        return JSONObject.parseObject(result, new TypeReference<>() {
        });
    }
}
